package com.googlecode.microanalyst.designer.model.commands;

import com.googlecode.microanalyst.designer.model.AnalysisConnection;
import com.googlecode.microanalyst.designer.model.AnalysisConnectionBendpoint;

public class MoveBendpointCommand extends BendpointCommand {

	private AnalysisConnectionBendpoint oldBendpoint;

	public void execute() {
		AnalysisConnectionBendpoint bp = new AnalysisConnectionBendpoint();
		bp.setRelativeDimensions(getFirstRelativeDimension(),
				getSecondRelativeDimension());
		AnalysisConnection c = getConnection();
		int idx = getIndex();
		setOldBendpoint(c.getBendpoints().get(idx));
		c.setBendpoint(idx, bp);
		super.execute();
	}

	protected AnalysisConnectionBendpoint getOldBendpoint() {
		return oldBendpoint;
	}

	public void setOldBendpoint(AnalysisConnectionBendpoint bp) {
		oldBendpoint = bp;
	}

	public void undo() {
		super.undo();
		int idx = getIndex();
		AnalysisConnectionBendpoint obp = getOldBendpoint();
		getConnection().setBendpoint(idx, obp);
	}

}
